from collections import defaultdict


class Solution(object):
    def fourSumCount(self, nums1, nums2, nums3, nums4):
        # 使用字典存储nums1和nums2中的元素及其和
        hashmap = defaultdict(int)
        for n1 in nums1:
            for n2 in nums2:
                hashmap[n1 + n2] += 1

        # 如果 -(n1+n2) 存在于nums3和nums4, 存入结果
        count = 0
        for n3 in nums3:
            for n4 in nums4:
                key = - n3 - n4
                if key in hashmap:
                    count += hashmap[key]
        return count

print(Solution().fourSumCount([1,2], [-2,-1],[-1,2],[0,2]))